package com.jlboot.core.base;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wangsanfei
 * @version 1.0
 * Create by 2024/2/29 19:18
 */
@Data
public class BaseSearchDto {

    private Integer page=1;

    private Integer limit=1000;

    private String orderBy;

    /**
     * _eq
     * _like
     *
     */
    private Map<String,Object> search=new HashMap<>();

    public void addSearch(String opt,Object value){
        search.put(opt,value);
    }

    /**
     * 用于创建缓存Key
     * @return
     */
    public String getCacheId(){
        StringBuilder cacheKey=new StringBuilder();
        cacheKey.append(page+"_");
        cacheKey.append(limit+"_");
        cacheKey.append(orderBy+"_");
        for (String key : search.keySet()) {
            Object value=search.get(key);
            if(value!=null){
                cacheKey.append(key+":"+value.toString()+"_");
            }
        }
        return cacheKey.toString();
    }

}
